﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;

namespace Zxb.DayWork.Service
{
    public partial class StatisticsService : ServiceBase
    {
        public StatisticsService()
        {
            InitializeComponent();
        }

        protected override void OnStart(string[] args)
        {
#if DEBUG
            Debugger.Launch(); //Launches and attaches a debugger to the process.
#endif
            try
            {
                BackgroundWorker worker = new BackgroundWorker();
                worker.DoWork += new DoWorkEventHandler(worker_DoWork);
                worker.RunWorkerAsync();
                Zxb.DayWork.Core.Logger.InfoLog.Info("服务已成功启动");
            }
            catch (Exception ex)
            {
                Zxb.DayWork.Core.Logger.InfoLog.Error(ex.Message);
            }
        }

        protected override void OnStop()
        {
            try
            {
                DayWorkTimer.stopTimer();
                Zxb.DayWork.Core.Logger.InfoLog.Info("服务已成功停止");
            }
            catch (Exception ex)
            {
                Zxb.DayWork.Core.Logger.InfoLog.Error(ex.Message);
            }
        }

        void worker_DoWork(object sender, DoWorkEventArgs e)
        {
            DayWorkTimer.initTimer();
        }
    }
}
